package com.api.regression.group.uploadnewdocument;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.api.test.AssertApi;
import com.api.test.UrnType;
import com.zyncro.api.IGroupApiService;
import com.zyncro.api.exceptions.ZyncroApiException;
import com.zyncro.api.model.ObjectResultApi;
import com.zyncro.api.model.UploadDocumentResultApi;

@ContextConfiguration(locations = { "classpath:/group/group-upload.xml" })
public class UploadNewDocumentWithoutQuota extends AbstractApiTest {

	@Value("#{group_toUploadQuota[owner].appId}")
	private String userUrn;

	@Value("#{group_toUploadQuota[owner].password}")
	private String userPassword;

	@Value("#{group_toUploadQuota.urn}")
	private String groupUrn;

	@BeforeClass
	protected void setParameters() throws Exception {

		getApi().login(userUrn, userPassword);
	}

	@Test(expectedExceptions = ZyncroApiException.class)
	public void testUploadGroup() throws ZyncroApiException, FileNotFoundException {

		File file = new File("FileName.txt");

		Long length = file.length();
		String fileName = file.getName();

		FileInputStream inputStream = new FileInputStream(file);

		String descriptionQuery = "A description";
		String commentQuery = null;
		String parentDocumentUrn = null;
		String description = null;
		String comment = null;

		@SuppressWarnings("deprecation")
		ObjectResultApi<UploadDocumentResultApi> result = getApi().getService(IGroupApiService.class).uploadNewDocument(groupUrn,
				getApi().getAccessKey(), descriptionQuery, commentQuery, parentDocumentUrn, description, comment, fileName, length,
				inputStream);
		UploadDocumentResultApi document = result.getObject();

		AssertApi.assertUrnType(document.getDocumentUrn(), UrnType.DOCUMENT);
	}
}
